package com.xsomnus.open.zookeeper.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author @xsomnus666_xiawenye★
 * @since 2019/4/18 0018 13:35
 * 当你发现自己的才华撑不起野心时，就请安静下来学习吧
 */
@Slf4j
@Configuration
@EnableConfigurationProperties(value = {ZookeeperProperties.class})
@ConditionalOnProperty(value = {"zookeeper.enabled"}, matchIfMissing = false)
public class ZkConfiguration {


    @Autowired
    ZookeeperProperties zookeeperProperties;

    @Bean(initMethod = "init", destroyMethod = "stop")
    public ZkClient zkClient() {
        log.debug("zookeeper配置信息: {}", zookeeperProperties);
        return new ZkClient(zookeeperProperties);
    }


}
